package org.chl.chapter09;

import java.util.List;

import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Repository;

@Repository
@CacheConfig(cacheNames = { "book_cache" })
public class BookDao {

	@CachePut(key = "#book.id")
	public Book updateBook(Book book) {
		book.setName("修改实体后_缓存自动变了" + System.currentTimeMillis());
		return book;
	}

	@CacheEvict
	public void deleteBookById(Integer id) {
	}

	@Cacheable
	public Book getBookById(Integer id) {
		System.out.println("getBookById=" + id);
		Book book = new Book();
		book.setId(id);
		book.setName("name");
		book.setAuthor("author");
		return book;
	}

	public List<Book> getAllBooks() {

		return null;
	}

}
